package com.meixiang.adapter.myFundAdapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.fund.FundInfoBean;
import com.meixiang.entity.fund.FundNewSerchResult;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * author:xyj
 */
public class FundSearchDataAdapter extends com.meixiang.recyclerview.RecyclerAdapter<FundSearchDataAdapter.ViewHolder> {
    private Context mContext;
    private List<FundNewSerchResult.FundInfoEntity> searchResult;

    public FundSearchDataAdapter(Context context) {
        this.mContext = context;
    }

    /**
     * 刷新数据
     */
    public void refreshData(List<FundNewSerchResult.FundInfoEntity> list) {
        searchResult = list;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_fund_screen_search_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tv_fund_search_number.setText(searchResult.get(position).getFund_id());
        holder.tv_fund_search_name.setText(searchResult.get(position).getFund_name());
        holder.tv_fund_search_class.setText(searchResult.get(position).getFund_type());
    }

    @Override
    public int getItemCount() {
        return searchResult == null?0:searchResult.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_fund_search_number)
        TextView tv_fund_search_number;
        @Bind(R.id.tv_fund_search_name)
        TextView tv_fund_search_name;
        @Bind(R.id.tv_fund_search_class)
        TextView tv_fund_search_class;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
